﻿using System;
using System.Drawing;
using RRRSRoguelike.Enums;
using RRRSRoguelike.Helpers.Visualizer;
using RRRSRoguelike.Managers;

namespace RRRSRoguelike.Screens
{
	/// <summary>
	/// Manages the UI to handle quiting the game.
	/// </summary>
	class QuitScreen : Screen
	{
		Panel MainPanel;
		bool YesNo;

		public QuitScreen()
		{
			PanelList.Add(new Panel(new Point(4, 3),
				  Visualizer.GetScreenWidth() - 9, Visualizer.GetScreenHeight() - 6));

			MainPanel = PanelList[0];
		}

		public bool ShowYesNo(DungeonScreen ds)
		{
			YesNo = false;

			Show(ds);

			return YesNo;
		}

		public void Show(DungeonScreen ds)
		{
			Clear();

			MainPanel.Draw();

			MainPanel.Write(Properties.Strings.Quit, 0, ConsoleColor.White, TextAlignment.Multi);

			ConsoleKey quit = Console.ReadKey(true).Key;
			if (quit.Equals(ConsoleKey.Y))
			{
				//Testing if this is needed
				//DungeonManager.Instance.gameOver = true;
				YesNo = true;
				ReplayScreen s = new ReplayScreen(ds);
				if (s.ShowYesNo())
				{
					//Do nothing and fall through
				}
				else
				{
					//MainPanel.Draw();
					//MainPanel.Write("See you later!");
					//WaitKey();
					//GameManager.Instance.Exit();
					//DungeonManager.Instance.Initialize();

					GameManager.Instance.ScreenStack.Push(new MenuScreen());
				}
			}
			else
			{
				MainPanel.Clear();
				//MainPanel.Write("Keep playing");

				DungeonManager.Instance.ForceRedraw();
			}
			GameManager.Instance.SoundManager.PlaySound(SoundList.Pluck.ToString());
		}
	}
}
